// Package main
// desc: x
// author: Locker
// date: 2024/8/22
// version: 1.0.0
package main

import (
	"crypto/md5"
	"encoding/hex"
	"io"
	"log"
	"os"
)

func main() {

	//filePath := "/opt/asl-aaa/test/update/20240821/GitEgg-main.zip"
	//url := "https://119.3.227.27:29004/docker/2.0.0/base/GitEgg-main.zip"

	filePath := "/opt/asl-aaa/test/update/20240821/AdminLTE3%20-video-20231026172057.mp4"
	url := "https://119.3.227.27:29004/docker/2.0.0/base/AdminLTE3%20-video-20231026172057.mp4"

	var retryCount int
	reader := NewReader()
	for retryCount < 10 {
		err := Resume(filePath, url, reader)
		if err != nil {
			retryCount += 1
			log.Printf("download fail on [%s], err: %v\n", reader.GetRate(), err)
		} else {
			break
		}
	}

	// 计算MD5
	f, err := os.Open(filePath)
	if err != nil {
		log.Printf("open file fail: %v\n", err)
		return
	}
	hash := md5.New()
	io.Copy(hash, f)
	md5Val := hex.EncodeToString(hash.Sum(nil))
	log.Printf("md5: %s", md5Val)

	//err := Resume(filePath, url)
	//if err != nil {
	//	log.Printf("download fail: %v\n", err)
	//}

}
